<template>
  <div class="editor-wrapper">
    <div id="editorId"></div>
  </div>
</template>

<script>
import Editor from "wangeditor";
export default {
  name: "Editor",
  props: {
    contentBody: {
      type: String,
      default: () => null
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      textValue: null,
      editor: null,
      isChange: false
    };
  },
  watch: {
    contentBody: {
      immediate: true,
      handler (val) {
        if (val !== "") {
          // bug【ID1004068】2020.1.15 企业版-报价系统-电子合同-起草合同：输入合同内容输入空格按键有误
          if (!this.isChange) this.editor?.txt.html(this.contentBody);
        }
      }
    }
  },
  mounted () {
    this.editor = new Editor(`#editorId`);
    this.editor.customConfig.zIndex = 1;
    this.editor.customConfig.onchange = (html) => {
      this.isChange = true;
      this.$emit("update:contentBody", html);
    };
    this.editor.create();
    this.editor.txt.html(this.contentBody);
  }
};
</script>
